package model;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.Writer;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Hashtable;

/**
 *
 * @author Barlas Karahocaoglu - The Purple Elephant
 */
public class QRCode {
 public static void generateQRCode(String url, String name, String path, String extension, int size, int errorCorrection, boolean shortenURL) {
        BitMatrix bitMatrix;
        Writer writer = new QRCodeWriter();
        try {
        	Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
        	hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            bitMatrix = writer.encode(url, BarcodeFormat.QR_CODE, 200, 200, hintMap);
            MatrixToImageWriter.writeToStream(bitMatrix, extension, new FileOutputStream(new File(name+"."+extension)));
            System.out.println("QR Code Generated.");
        } catch (Exception e) {
            System.out.println("Exception Found." + e.getMessage());
        }

    }
}